<!DOCTYPE html>
<html lang="en">
<head>
    <#include "segment/header.html">
</head>

<body class="no-skin">
<#include "segment/navbar.html">

<div class="main-container ace-save-state" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.loadState('main-container')
        } catch (e) {
        }
    </script>

    <div class="main-content">
        <div class="main-content-inner">
            <#include "segment/breadcrumbs.html">
            <#include "segment/sidebar.html">
            <div class="page-content">
                <div class="row">
                    <div class="col-md-12">
                        <div class="page-header">
                            <h1>
 								${department.name}
                                <i class="ace-icon fa fa-angle-double-right"></i>
                                <small>文章管理</small>
                            </h1>
                        </div>
                        <div class="row">
                            <div class="col-md-4 col-md-offset-1">
                            	<a href="${basePath}/admin/article/add" class="btn btn-sm btn-success"> 
                                    <i class="ace-icon fa fa-pencil align-top bigger-125"></i>
									添加新文章
                                </a>
                                <a href="#" class="btn btn-sm btn-danger">
                                    <i class="ace-icon fa fa-trash-o bigger-125"></i>
 									删除
                                </a>
                            </div>
                        </div>
                        <div class="space-4"></div>
                        <div class="row">
                            <div class="col-md-12">
                                <table id="article-table" class="table table-hover table-bordered table-responsive">
                                    <thead>
                                        <tr>
                                            <th class="center">
                                                <label class="pos-rel">
                                                    <input type="checkbox" class="ace">
                                                    <span class="lbl"></span>
                                                </label>
                                            </th>
                                            <th>id</th>
                                            <th class="col-md-2">标题</th>
                                            <th class="col-md-5">内容摘要</th>
                                            <th>所属部门</th>
                                            <th>发布人</th>
                                            <th>发布时间</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>	
                                    	<#assign pageInfo=("pageInfo"+department.id)?eval/>
	                                    <#list pageInfo.list as a>
	                                        <tr>
	                                            <td class="center">
	                                                <label class="pos-rel">
	                                                    <input type="checkbox" class="ace">
	                                                    <span class="lbl"></span>
	                                                </label>
	                                            </td>
	                                            <td>${a.id}</td>
	                                            <td><@t.cut a.title 13 /></td>
	                                            <td><@t.cut a.content 38 /></td>
	                                            <td>${department.name}</td>
	                                            <td>${Session.user.nickName}</td>
	                                            <td>${a.publishDate?string("yyyy-MM-dd hh:mm:ss")}</td>
	                                            <td>
	                                                <a href="${basePath}/admin/article/edit/${a.id}?pn=${pageInfo.pageNum}" class="btn btn-minier btn-success">
														编辑
	                                                </a>
	                                                <a class="btn btn-minier btn-danger">
														删除
	                                                </a>
	                                            </td>
	                                        </tr>
	                                    </#list> 
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="row">
                        	<div class="col-md-6">
                        		<div class="pull-right">
	                        	<ul class="pagination">
	                        		<li><h5>当前显示${pageInfo.startRow}-${pageInfo.endRow}条记录，共${pageInfo.total}条记录，共${pageInfo.pages}页 </h5></li>
	                        	</ul>
	                        	</div>
                        	</div>
                        	<div class="col-md-6">
								<ul class="pagination">
									<li>
										<a href="${basePath}/admin/article/list/${department.id}?pn=1">首页</a>
									</li>
									<#if pageInfo.hasPreviousPage ==false>
										<li class="disabled">
											<a href="#">
												<i class="ace-icon fa fa-angle-double-left"></i>
											</a>
										</li>
									<#else>
										<li>
											<a href="${basePath}/admin/article/list/${department.id}?pn=${pageInfo.prePage}">
												<i class="ace-icon fa fa-angle-double-left"></i>
											</a>
										</li>
									</#if>
									<#list pageInfo.navigatepageNums as p>
										<#if p=pageInfo.pageNum>
											<li class="active">
												<a href="#">${p}</a>
											</li>
										<#else>
											<li>
												<a href="${basePath}/admin/article/list/${department.id}?pn=${p}">${p}</a>
											</li>
										</#if>
									</#list>
									<#if pageInfo.hasNextPage ==false>
										<li class="disabled">
											<a href="#">
												<i class="ace-icon fa fa-angle-double-right"></i>
											</a>
										</li>
									<#else>
										<li>
											<a href="${basePath}/admin/article/list/${department.id}?pn=${pageInfo.nextPage}">
												<i class="ace-icon fa fa-angle-double-right"></i>
											</a>
										</li>
									</#if>
									<li>
										<a href="${basePath}/admin/article/list/${department.id}?pn=${pageInfo.pages}">末页</a>
									</li>
								</ul>
                        	</div>
                        </div>
                    </div>
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <#include "segment/footer.html">
</div><!-- /.main-container -->
<#include "segment/scripts.html">
<script type="text/javascript">
    jQuery(function($) {
	    //勾选标题行复选框，选择表格中所有行
	    $('#article-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function(){
	        var th_checked = this.checked;//checkbox inside "TH" table header
	
	        $(this).closest('table').find('tbody > tr').each(function(){
	            var row = this;
	            if(th_checked) $(row).addClass('active').find('input[type=checkbox]').eq(0).prop('checked', true);
	            else $(row).removeClass('active').find('input[type=checkbox]').eq(0).prop('checked', false);
	        });
	    });
	
	    //select/deselect a row when the checkbox is checked/unchecked
	    $('#article-table').on('click', 'td input[type=checkbox]' , function(){
	        var $row = $(this).closest('tr');
	        if($row.is('.detail-row ')) return;
	        if(this.checked) $row.addClass('active');
	        else $row.removeClass('active');
	    });
    });
</script>
</body>
</html>
